// Package service /*APP的主体结构
package service

import (
	"runtime"
	"strings"

	cf "godocker/common/functions"
)

type app struct {
	SName    string
	basicDir []string
}

func appNew() *app {

	return &app{
		"app",
		[]string{
			installDir + "/lib",    //镜像数据存放
			installDir + "/worker", //代码运行环境
			ymlDir,                 //docker文件存放处
		},
	}
}

func (a app) install() {
	a.mkdir()
	a.setPackr()
}

func (a app) mkdir() {
	//创建app目录
	cf.MakeDir(installDir)

	//创建基础目录
	for i := 0; i < len(a.basicDir); i++ {
		cf.MakeDir(a.basicDir[i])
	}
}

func (a app) setPackr() {
	var name, file string

	switch strings.ToLower(runtime.GOOS) {
	case "windows":
		name = "packr.exe"
	case "linux":
		name = "packr"
	}

	file = cf.GetDockerfile(name)

	cf.WriteToFileTrunc(installDir+"/worker/golang/bin/"+name, file)
}
